package cn.wolfcode.web.controller;

import cn.wolfcode.domain.Appointment;
import cn.wolfcode.domain.JsonResult;
import cn.wolfcode.enums.AppointmentStatusEnum;
import cn.wolfcode.service.IAppointmentService;
import cn.wolfcode.service.IBusinessService;
import cn.wolfcode.service.ISystemDictionaryItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/frontend")
public class indexController {
    @Autowired
    private IBusinessService businessService;
    @Autowired
    private ISystemDictionaryItemService systemDictionaryItemService;
    @Autowired
    private IAppointmentService appointmentService;

    @RequestMapping("/index")
    public String index(Model model) {
        //业务大类
        model.addAttribute("business", systemDictionaryItemService.queryBySn("business"));
        model.addAttribute("mainStore", businessService.selectMainStore());
        //门店集合
        model.addAttribute("stores", businessService.listAll());
        return "index";
    }

    @RequestMapping("appointment/save")
    @ResponseBody
    public JsonResult save(Appointment appointment) {
        JsonResult jsonResult = new JsonResult();
        //设置状态为待确认
        appointment.setStatus(AppointmentStatusEnum.PEND.getValue());
        appointmentService.save(appointment);
        return jsonResult;
    }
}
